package com.itheima.controller;

import com.itheima.dto.PageArticles;
import com.itheima.dto.YddArticleDTO;
import com.itheima.result.PageData;
import com.itheima.result.R;
import com.itheima.service.YddArticleService;
import com.itheima.vo.YddArticleVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: YddArticleController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/23 21:19
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/ydd_article")
@AllArgsConstructor
public class YddArticleController {
    private final YddArticleService yddArticleService;

    /**
     * pag
     *
     * @param pageArticles 页面文章
     * @return {@link R}<{@link PageData}>
     */
    @GetMapping("/list")
    public R<PageData> pag(PageArticles pageArticles){
        PageData pageData = yddArticleService.pag(pageArticles);
        return R.success(pageData);
    }

    /**
     * 创建文章
     *
     * @return {@link R}<{@link YddArticleVO}>
     */
    @PostMapping("/add")
    public R<?> creatArticle(@RequestBody YddArticleDTO yddArticleDTO){
        yddArticleService.creatArticle(yddArticleDTO);
        return R.success();
    }

    /**
     * 查询文章
     *
     * @param id id
     * @return {@link R}<{@link YddArticleVO}>
     */
    @GetMapping("/rowInfo")
    public R<YddArticleVO> queryArticle(Integer id){
        YddArticleVO yddArticleVO = yddArticleService.queryArticle(id);
        return R.success(yddArticleVO);
    }

    /**
     * 更新文章
     *
     * @param yddArticleDTO ydd文章do
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> updateArticle(@RequestBody YddArticleDTO yddArticleDTO){
        yddArticleService.updateArticle(yddArticleDTO);
        return R.success();
    }

    /**
     * 删除文章
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/del")
    public R<?> deleteArticle(Integer id){
        yddArticleService.deleteArticle(id);
        return R.success();
    }
}
